package com.wise.model.content.utils;

import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author hejiawei
 * @date 2020/9/23 13:27
 */
public class AnsjUtil {

    /**
     * 获取分词
     *
     * @param query
     * @return
     */
    public static List<Term> getAnsj(String query) {
        Result result = ToAnalysis.parse(query);
        List<Term> terms = result.getTerms();

        return terms.stream().filter(it -> !StringUtils.equals(it.getName(), " "))
                .distinct()
                .collect(Collectors.toList());
    }


}
